from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtWidgets import QWidget, QGroupBox

def set_transparent_background(window):
    """设置透明背景效果"""
    # 设置窗口背景透明
    window.setAttribute(Qt.WA_TranslucentBackground)
    
    # 设置窗口背景色
    palette = window.palette()
    palette.setColor(QPalette.Window, QColor(255, 255, 255, 200))  # 半透明白色
    window.setPalette(palette)

def apply_content_styles(main_window):
    """应用内容区域样式"""
    # 设置内容区域样式
    main_window.content_stack.setStyleSheet("""
        QTabWidget::pane {
            border: 1px solid #cccccc;
            border-radius: 5px;
            background-color: rgba(255, 255, 255, 220);
        }
        
        QGroupBox {
            border: 1px solid #cccccc;
            border-radius: 5px;
            margin-top: 1ex;
            background-color: rgba(255, 255, 255, 180);
        }
        
        QGroupBox::title {
            subcontrol-origin: margin;
            subcontrol-position: top center;
            padding: 0 3px;
            background-color: rgba(255, 255, 255, 200);
        }
    """)
    
    # 为每个页面应用样式
    for i in range(main_window.content_stack.count()):
        page_widget = main_window.content_stack.widget(i)
        apply_page_background(page_widget)

def apply_page_background(widget):
    """应用页面背景样式"""
    widget.setStyleSheet("""
        QWidget {
            background-color: rgba(255, 255, 255, 220);
            border-radius: 5px;
        }
    """)
    
    # 递归应用到子控件
    for child in widget.findChildren(QGroupBox):
        child.setStyleSheet("""
            QGroupBox {
                border: 1px solid #cccccc;
                border-radius: 5px;
                margin-top: 1ex;
                background-color: rgba(255, 255, 255, 180);
            }
            
            QGroupBox::title {
                subcontrol-origin: margin;
                subcontrol-position: top center;
                padding: 0 3px;
                background-color: rgba(255, 255, 255, 200);
            }
        """)
